package Service;

import Dao.DepartmentDao;
import org.example.Department;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class DepartmentService {
    static DepartmentService departmentService = null;
    static DepartmentDao departmentDao = new DepartmentDao();

    public static DepartmentService getInstance(){
        if (departmentService == null){
            departmentService = new DepartmentService();
        }
        return departmentService;
    }

    private  DepartmentService(){}


    public Collection<Department> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Collection<Department> departments = departmentDao.findAll(connection,conditionList,pagination);
        JdbcHelper.close(connection);
        return departments;
    }


    public Department add(Department department) throws SQLException {
        department= departmentDao.add(department);
        return department;
    }

    public Department update(Department department) throws SQLException {
        department = departmentDao.update(department);
        return department;
    }

    public Department delete(Department department) throws SQLException {
        department = departmentDao.delete(department);
        return department;
    }
    /*@Override
    public Teacher find(int id) throws SQLException {
        Teacher teacher = teacherDao.find(id);
        return teacher;
    }*/
}
